package com.wkr.order.aop;

import io.seata.core.context.RootContext;
import io.seata.tm.api.GlobalTransactionContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 服务熔断要手动回滚seata事务
 */
@Aspect
public class SeataRollBackAspect {

    @Pointcut("execution(* com.wkr.order.service.fallback.*.*(..))")
    public void feignFallBack() {

    }

    @Around("feignFallBack()")
    public Object seataFeign(ProceedingJoinPoint joinPoint) throws Throwable {
        //手动回滚
        GlobalTransactionContext.reload(RootContext.getXID()).rollback();
        return joinPoint.proceed();
    }
}
